package com.edu.service.impl;

import com.edu.mapper.UserMapper;
import com.edu.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/*
 * @Author:mx
 * @Date:2025/11/18-15:11:10
 */

/*
*   配置好之后 @Transactional注解 可以放在 业务类的上面 /业务方法的上面
*       业务类上面： 这个业务类的每一个方法  都要开启事务执行
*       业务方法上面:  只是这一个方法 要开启事务执行
* */
@Service

public class UserServiceImpl2 implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
//    @Transactional(timeout = 5)
    public int transferMoney(int userId1, int userId2, double money) {
       int result1 = userMapper.updateUserMoney(userId1,-money);
        try {
            Thread.sleep(6000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        int result2 = userMapper.updateUserMoney(userId2,money);
       return result1+result2 == 2 ?  1 : 0;
    }


}
